<?php

namespace app\index\controller;

class Domain extends Base
{

    public function index($navid = null)
    {
        $domain = $this->request->post();
        if (!empty($domain['dns']) && !empty($domain['ext'])) {
            $domain_name = null;
            //遍历所有的域名
            foreach ($domain['ext'] as $datakey => $value) {
                //组合域名
                $dns = $domain['dns'] . "." . $value;

                //查询：
                $domain_name[$datakey]['name'] = $dns;
                $do = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" . $dns;
                $xml_data = file_get_contents($do);
                $result_arr = (array)simplexml_load_string($xml_data);

                $original = $result_arr['original'];

                $status = substr($original, 0, 3);

                if ($status == "210") {

                    $domain_name[$datakey]['value'] = "：<font color='green'>恭喜您,可以注册</font>";

                } else if ($status == "211") {

                    $domain_name[$datakey]['value'] = "：<font color='red'>已经注册</font>";

                } else if ($status == "212") {

                    $domain_name[$datakey]['value'] = "：<font color='red'>参数错误</font>";

                }
            }
            return json($domain_name);
//            $this->assign('domain_name',$domain_name);
        } else {
            return $this->error('提交的数据不完整');
        }
    }

    public function postindex($navid = null)
    {
        $domain = $this->request->post();
        if (!empty($domain['dns']) && !empty($domain['ext'])) {
            $domain_name = null;
            //组合域名
            $dns = $domain['dns'] . "." . $domain['ext'];

            //查询：
            $domain_name['name'] = $dns;
            $do = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" . $dns;
            $xml_data = file_get_contents($do);
            $result_arr = (array)simplexml_load_string($xml_data);

            $original = $result_arr['original'];

            $status = substr($original, 0, 3);

            if ($status == "210") {

                $domain_name['value'] = "：<font color='green'>恭喜您,可以注册</font>";

            } else if ($status == "211") {

                $domain_name['value'] = "：<font color='red'>已经注册</font>";

            } else if ($status == "212") {

                $domain_name['value'] = "：<font color='red'>参数错误</font>";
            }
            $this->assign('domain_name', $domain_name);
            return $this->fetch($this->template . 'domain.html');
        } else {
            return $this->error('提交的数据不完整');
        }
    }


}
